package com.shu.lock;

import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.TransferQueue;

/**
 * @author ssm
 * @version V1.0
 * @description:
 * @date 2020/8/27 11:17
 */

public class TransferQueueTest {


    public static void main(String[] args) {

        char[] a1 = "123456".toCharArray();
        char[] b1 = "abcdef".toCharArray();

        TransferQueue<Character> queue = new LinkedTransferQueue<>();

        new Thread(() -> {
            try {
                for (final char c : a1) {
                    System.out.println(queue.take());
                    queue.transfer(c);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t1").start();


        new Thread(() -> {
            try {
                for (final char c : b1) {
                    queue.transfer(c);
                    System.out.println(queue.take());
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t2").start();



    }
}
